const { list } = require('./mock')
const bodyParser = require('body-parser');
module.exports = app => {
	app.use(bodyParser.json())
	// 列表
	app.get('/api/list', (req, res) => res.send({ code: 200, data: list }))
	// 详情
	app.post('/api/detail', (req, res) => {
		const { id } = req.body;

		const item = list.find(v => {
			return v.id === id 
		})

		res.send({
			code: 200,
			data: item,
			html: `
				<div>
					<h3>${item.title}</h3>
					<img src=${item.url} alt="" width="100%" />
					<p>${item.desc}</p>
					<p>单价：${item.price}</p>
				</div>
			`
		})
	})	
}